package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface SetmealMapper {
	
	/**
	 * 分页查询套餐
	 */
	
	Page<SetmealVO> getSetmeal(SetmealPageQueryDTO setmealPageQueryDTO);
	
	/**
	 * 根据分类id查询套餐数量
	 *
	 * @param categoryId
	 * @return
	 */
	@Select("select count(*) from setmeal where category_id=#{categoryId}")
	Integer getSetmealCategory(Long categoryId);
	
	/**
	 * 根据分类id查询套餐
	 *
	 * @param categoryId
	 * @return
	 */
	@Select("select * from setmeal where category_id=#{categoryId}")
	List<Setmeal> getSetmealCategoryId(Long categoryId);
	
	/**
	 * 添加套餐
	 *
	 * @param setmeal
	 */
	@AutoFill(OperationType.INSERT)
	void addSetmeal(Setmeal setmeal);
	
	/**
	 * 根据id查询套餐
	 *
	 * @param id
	 */
	@Select("select * from setmeal where id = #{id}")
	Setmeal getSetmealId(Long id);
	
	/**
	 * 修改套餐状态
	 *
	 * @param id
	 * @param status
	 * @param updateTime
	 * @param updateUser
	 */
	@Update("update setmeal set status = #{status},update_time=#{updateTime},update_user=#{updateUser} where id = #{id}")
	void putSetmealStatus(Long id, Integer status, LocalDateTime updateTime, Long updateUser);
	
	void deleteSetmeal(List<Long> ids);
	
	@AutoFill(OperationType.UPDATE)
	void putSetmeal(Setmeal setmeal);
	
	@Select("select count(*) from setmeal where status=#{status}")
	Integer countNumber(Integer status);
}
